package cn.tedu.aiumall.product.webapi.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

import java.io.Serializable;
//redis配置类配置详情
@Slf4j
@Configuration
public class RedisConfiguration {
    //key的泛型为String，value的泛型为可序列化数据类型
    @Bean
    public RedisTemplate<String, Serializable> redisTemplate(
            RedisConnectionFactory redisConnectionFactory
    ){
            RedisTemplate<String,Serializable> redisTemplate=
                    new RedisTemplate<>();
            //key序列器
            redisTemplate.setKeySerializer(RedisSerializer.string());
            //值序列器
            redisTemplate.setValueSerializer(RedisSerializer.json());
            //连接工厂
            redisTemplate.setConnectionFactory(redisConnectionFactory);

            return redisTemplate;
    }
}
